<template>
<!-- 对账周期 -->
    <div class="settlement-mode">
        <el-radio-group :disabled="readonly" v-model="checkedData" @change="changeData">
            <el-radio v-for="item in options" :label="item.code" :key="item.code">{{ item.name }}</el-radio>
        </el-radio-group>
    </div>
</template>

<script>
import nonStandardService from '@/services/nonStandardService'
export default {
    name: 'accountCycle',
    props: {
        detail: {
            type: Object,
            default: () => {
                return {}
            } 
        },
        value: {},
        disabled: Boolean,
        parameter: {
            type: Object,
            default: () => {
                return {}
            } 
        } 
    },
    data(){
        return {
            options: [],
            checkedData: null,
            selectData: null,
            readonly: false,
        }
    },
    created(){
        this.readonly = Boolean(this.$route.query.readonly) || this.disabled;
        this.queryData();
        if(this.value){
            this.setData();
        }
    },
    methods: {
        queryData(){
            /**
             * code 对账周期 accountCycle
             * ecology 生态 多式联运: TMS 仓储:WMS
             * memberType 货主:1 承运商:3 司机:4 车老板:5 仓储货主 :6
             * industry 行业 通用 :1 行业:2
             */
            let params = { 
                code: 'accountCycle',
            };
            let templateTypeCode = this.detail.templateTypeCode;
            params.templateTypeCode = templateTypeCode;
            switch (templateTypeCode) {
                case 'TMSHZ': //多式联运货主
                    params.ecology = 'TMS';
                    params.memberType = 1;
                    break;
                case 'TMSCYS': //多式联运承运商
                    params.ecology = 'TMS';
                    params.memberType = 3;
                    break;
                case 'TMSSJ': //多式联运个体司机
                    params.ecology = 'TMS';
                    params.memberType = 4;
                    break;
                case 'TMSCLB': //多式联运车老板
                    params.ecology = 'TMS';
                    params.memberType = 5;
                    break;
                case 'WMSHZ1': //仓储货主（通用）
                    params.ecology = 'WMS';
                    params.memberType = 6;
                    params.industry = 1;
                    break;
                case 'WMSHZ2': //仓储货主（行业）
                    params.ecology = 'WMS';
                    params.memberType = 6;
                    params.industry = 2;
                    break;
            }
            // 接口
            nonStandardService.basicConfiguration(params).then(res => {
                if(res.code == 200){
                    this.options = res.data;
                }
            })
        },
        changeData(val){
            let info = this.options.find(it => it.value == val) || {};
            this.selectData = info.name;
            this.$emit("input",this.checkedData);
        },
        getData(){
            return {
                value: this.selectData,
                checkedData: this.checkedData,
            }
        },
        setData(){
            this.selectData = JSON.parse(this.value).value;
            this.checkedData = JSON.parse(this.value).checkedData;
        },
    }
}
</script>

<style lang="scss">
.settlement-mode {
    .el-select {
        width: 100%;
    }
}
</style>